#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *print_message_function( void *ptr );
void execute_threads(int thread_count)

main()
{
     execute_threads(2);
}

void *print_message_function( void *ptr )
{
     char *message;
     message = (char *) ptr;
     printf("%s \n", message);
}

void execute_threads(int thread_count)
{
     pthread_t *threads = malloc(sizeof(pthread_t)*thread_count);
     char *message = "Change me to an integer!";
     int int *return_values = malloc(sizeof(int)*thread_count);
     /* Create independent threads each of which will execute function */

     for (int i = 0; i < thread_count; ++i)
     {
         return_values[i] = pthread_create(&(threads[i]), NULL, print_message_function, (void*) message);
     }
     /* Wait till threads are complete before main continues. Unless we  */
     /* wait we run the risk of executing an exit which will terminate   */
     /* the process and all threads before the threads have completed.   */
     for (int i = 0; i < thread_count; ++i)
     {
          pthread_join(threads[i], NULL);
     }
     for (int i = 0; i < thread_count; ++i)
     {
          printf("Thread %d returns %d\n", i, return_values[i]);
     }
     exit(0);

}
